﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/AdminSite.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="MensUnoShop.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	HanselSetup
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<style>
    table#coupon td{border:1px solid #ccc;}
</style>
<%
    var saleskit = ViewData["saleskit"] as USalesKit;
%>
<div id="main-content" class="hastable">
    <div class="title title-spacing">
	    <h2>買千折百活動管理</h2>
    </div>
<form action="" method="post">
    <input type="hidden" name="Act" value="<%:ViewData["Act"] %>">
<table id="coupon" style="width:700px;">
<tr>
    <th>活動名稱</th><td><input type="text" size="40" name="stitle" value="<%:saleskit==null?"":saleskit.SStitle %>"></td>
</tr>
<tr>
    <th>活動期間</th>
    <td>
        <input class="datepicker" name="startdate" type="text" id="startdate" size="10" readonly="readonly" value="<%:saleskit==null?"":saleskit.SSstartdate.Value.ToShortDateString() %>" />
        <input class="datepicker" name="enddate" type="text" id="enddate" size="10" readonly="readonly" value="<%:saleskit==null?"":saleskit.SSenddate.Value.ToShortDateString() %>" />
    </td>
</tr>
<%if(saleskit != null){ %>
<tr id="memo">
    <th>活動內容</th>
    <td>
        <table id="tb_handsel" style="width:250px;">
           <thead>
                <tr>
                    <td width="80">滿額</td><td>折抵金額</td><td>刪除</td>
                </tr>
            </thead>
            <tbody>
                
            </tbody>
        </table>
        <table style="margin:0px;">
                <tr>
                    <th>新增條件</th>
                    <td>滿額條件：<input type="text" name="limit" id="limit" /> | 折抵金額：<input type="text" name="giftpoint" id="giftpoint" /><input type="button" value="送出" onclick="addhandsel();" /></td>
                </tr>
        </table>
        
    </td>
</tr>
<%} %>
<tr><td colspan="2"><input type="submit" value="<%:ViewData["title"] %>" /></td></tr>
</table>
</form>

</div>
<div id="bk" style="width:100%;height:1000px;position:absolute; top:0px; left:0px;background-color:Black;z-index:999999;filter:alpha(opacity=50);-moz-opacity:0.5;opacity: 0.5;"></div>

<script type="text/javascript">
$("#bk").hide();
<%if(saleskit!=null){ %>
    $("#bk").show();
    $.ajax({
        type: "GET",
        traditional: true,
        url: "/Admin/SalesKit/api_handsel/<%:saleskit.SSguid %>",
        dataType: "json",
        success: function (data) {
            if (data.code == "200") {
                $("#tb_handsel tbody").remove();
                for (var i = 0; i < data.limit.length; i++) {
                    $("#tb_handsel").append('<tr><td class="center">'+data.limit[i]+'</td><td class="center">'+data.giftpoint[i]+'</td><td><input type="button" value="刪除" onclick="delhandsel('+data.shid[i]+')" /></td></tr>');
                }
            }
            else
                alert(data.response);
            $("#bk").hide();
        }
    });
    
    function addhandsel(){
        $("#bk").show();
        if(parseInt($("#limit").val())<parseInt($("#giftpoint").val())){
            alert('折扣金額大於購物金額!!!');
            $("#bk").hide();
        }
        else
        {
            $.ajax({
                type: "POST",
                traditional: true,
                url: "/Admin/SalesKit/api_handsel/<%:saleskit.SSguid %>",
                data: {"act":"Add","limit":$("#limit").val(),"giftpoint":$("#giftpoint").val()},
                dataType: "json",
                success: function (data) {
                    if (data.code == "200") {
                        $("#tb_handsel tbody").remove();
                        for (var i = 0; i < data.limit.length; i++) {
                            $("#tb_handsel").append('<tr><td class="center">'+data.limit[i]+'</td><td class="center">'+data.giftpoint[i]+'</td><td><input type="button" value="刪除" onclick="delhandsel('+data.shid[i]+')" /></td></tr>');
                        }
                    }
                    else
                        alert(data.response);
                    $("#bk").hide();
                }
            });
        }
    }

    function delhandsel(shid){
        $("#bk").show();
        $.ajax({
            type: "POST",
            traditional: true,
            url: "/Admin/SalesKit/api_handsel/<%:saleskit.SSguid %>",
            data: {"act":"Del","shid":shid},
            dataType: "json",
            success: function (data) {
                if (data.code == "200") {
                    $("#tb_handsel tbody").remove();
                        for (var i = 0; i < data.limit.length; i++) {
                            $("#tb_handsel").append('<tr><td class="center">'+data.limit[i]+'</td><td class="center">'+data.giftpoint[i]+'</td><td><input type="button" value="刪除" onclick="delhandsel('+data.shid[i]+')" /></td></tr>');
                        }
                }
                else
                    alert(data.response);
                $("#bk").hide();
            }
        });
    }
    
    <%} %>
</script>


</asp:Content>
